import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/utils/image_url.dart';

class ItemBean {
  String image;

  String name;

  String number;

  String specifications;

  ItemBean({this.image, this.name, this.number, this.specifications});
}

class MaterialListCard extends StatelessWidget {
  final List<ItemBean> list;
  final String logo;

  const MaterialListCard({Key key, this.list, this.logo}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> widgets = list.map((e) => createItem(e)).toList();
    return Card(
      elevation: 5,
      child: Container(
        child: Padding(
          padding: EdgeInsets.fromLTRB(20.w, 30.h, 20.w, 30.h),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(bottom: 30.h),
                child: CachedNetworkImage(
                  height: 25.h,
                  imageUrl: ImageUrlUtil.getClean(logo),
                  fit: BoxFit.fitHeight,
                ),
              ),
              ListView(
                physics: NeverScrollableScrollPhysics(),
                children: widgets,
                shrinkWrap: true,
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget createItem(ItemBean e) {
    return Container(
      margin: EdgeInsets.only(bottom: 30.h),
      height: 150.h,
      child: Row(
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(10.w),
            child: CachedNetworkImage(
              width: 150.w,
              height: 150.w,
              imageUrl: ImageUrlUtil.getClean(e.image, w: 150),
              fit: BoxFit.cover,
            ),
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(left: 20.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    e.name,
                    style: TextStyle(
                      fontSize: 32.sp,
                      color: Color(0xff333333),
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 30.h),
                    child: Row(
                      children: [
                        Text(
                          '编号：${e.number}',
                          style: TextStyle(fontSize: 28.sp, color: Color(0xff333333)),
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 30.w),
                          child: Text(
                            '规格：${e.specifications}',
                            style: TextStyle(fontSize: 28.sp, color: Color(0xff333333)),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
